namespace ProjectThuCung.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class AddClassLoaiThuCung : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.HoaDons",
                c => new
                    {
                        HoaDonID = c.Int(nullable: false, identity: true),
                        TenNguoiMua = c.String(nullable: false, maxLength: 56),
                        DienThoai = c.String(nullable: false, maxLength: 16),
                        DiaChi = c.String(nullable: false, maxLength: 128),
                        ThoiGianGiaoHang = c.DateTime(nullable: false),
                        Dagiao = c.Boolean(nullable: false),
                        TongTien = c.Single(nullable: false),
                        User_UserId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.HoaDonID)
                .ForeignKey("dbo.UserProfile", t => t.User_UserId, cascadeDelete: true)
                .Index(t => t.User_UserId);
            
            CreateTable(
                "dbo.UserProfile",
                c => new
                    {
                        UserId = c.Int(nullable: false, identity: true),
                        UserName = c.String(nullable: false, maxLength: 56),
                    })
                .PrimaryKey(t => t.UserId);
            
            CreateTable(
                "dbo.BaiViets",
                c => new
                    {
                        BaiVietID = c.Int(nullable: false, identity: true),
                        TenNguoiViet = c.String(nullable: false, maxLength: 56),
                        TieuDe = c.String(nullable: false, maxLength: 128),
                        NoiDung = c.String(nullable: false),
                        ThoiGian = c.DateTime(nullable: false),
                        NguoiViet_UserId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.BaiVietID)
                .ForeignKey("dbo.UserProfile", t => t.NguoiViet_UserId, cascadeDelete: true)
                .Index(t => t.NguoiViet_UserId);
            
            CreateTable(
                "dbo.BinhLuanBaiViets",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        UserName = c.String(nullable: false, maxLength: 56),
                        NoiDung = c.String(nullable: false, maxLength: 2000),
                        ThoiGian = c.DateTime(nullable: false),
                        BaiViet_BaiVietID = c.Int(),
                        UserProfile_UserId = c.Int(),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.BaiViets", t => t.BaiViet_BaiVietID)
                .ForeignKey("dbo.UserProfile", t => t.UserProfile_UserId)
                .Index(t => t.BaiViet_BaiVietID)
                .Index(t => t.UserProfile_UserId);
            
            CreateTable(
                "dbo.BinhLuanSanPhams",
                c => new
                    {
                        BinhLuanSanPhamID = c.Int(nullable: false, identity: true),
                        TenNguoiBinhLuan = c.String(nullable: false, maxLength: 56),
                        TieuDe = c.String(nullable: false, maxLength: 128),
                        NoiDung = c.String(nullable: false, maxLength: 2000),
                        ThoiGian = c.DateTime(nullable: false),
                        SanPham_SanPhamID = c.Int(),
                        User_UserId = c.Int(),
                    })
                .PrimaryKey(t => t.BinhLuanSanPhamID)
                .ForeignKey("dbo.SanPhams", t => t.SanPham_SanPhamID)
                .ForeignKey("dbo.UserProfile", t => t.User_UserId)
                .Index(t => t.SanPham_SanPhamID)
                .Index(t => t.User_UserId);
            
            CreateTable(
                "dbo.SanPhams",
                c => new
                    {
                        SanPhamID = c.Int(nullable: false, identity: true),
                        TenSanPham = c.String(nullable: false, maxLength: 56),
                        MoTa = c.String(maxLength: 3000),
                        Gia = c.Single(nullable: false),
                        SoLuong = c.Int(nullable: false),
                        XuatXu_XuatXuID = c.Int(),
                        LoaiSanPham_LoaiSanPhamID = c.Int(),
                        ThongTinThem_ThongTinThemID = c.Int(),
                    })
                .PrimaryKey(t => t.SanPhamID)
                .ForeignKey("dbo.XuatXus", t => t.XuatXu_XuatXuID)
                .ForeignKey("dbo.LoaiSanPhams", t => t.LoaiSanPham_LoaiSanPhamID)
                .ForeignKey("dbo.ThongTinThems", t => t.ThongTinThem_ThongTinThemID)
                .Index(t => t.XuatXu_XuatXuID)
                .Index(t => t.LoaiSanPham_LoaiSanPhamID)
                .Index(t => t.ThongTinThem_ThongTinThemID);
            
            CreateTable(
                "dbo.XuatXus",
                c => new
                    {
                        XuatXuID = c.Int(nullable: false, identity: true),
                        TenXuatXu = c.String(nullable: false, maxLength: 56),
                        DiaChi = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => t.XuatXuID);
            
            CreateTable(
                "dbo.LoaiSanPhams",
                c => new
                    {
                        LoaiSanPhamID = c.Int(nullable: false, identity: true),
                        TenLoaiSanPham = c.String(nullable: false, maxLength: 56),
                        ThuocTinh = c.String(nullable: false, maxLength: 3000),
                        SubLoaiSanPham = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.LoaiSanPhamID);
            
            CreateTable(
                "dbo.ThongTinThems",
                c => new
                    {
                        ThongTinThemID = c.Int(nullable: false, identity: true),
                        Giong = c.String(nullable: false, maxLength: 56),
                        GioiTinh = c.Boolean(nullable: false),
                        ThangTuoi = c.Int(nullable: false),
                        Mau = c.String(nullable: false, maxLength: 20),
                        TrongLuong = c.Single(nullable: false),
                    })
                .PrimaryKey(t => t.ThongTinThemID);
            
            CreateTable(
                "dbo.CTHoaDons",
                c => new
                    {
                        CTHoaDonID = c.Int(nullable: false, identity: true),
                        GiaBan = c.Single(nullable: false),
                        Soluong = c.Int(nullable: false),
                        HoaDon_HoaDonID = c.Int(),
                        SanPham_SanPhamID = c.Int(),
                    })
                .PrimaryKey(t => t.CTHoaDonID)
                .ForeignKey("dbo.HoaDons", t => t.HoaDon_HoaDonID)
                .ForeignKey("dbo.SanPhams", t => t.SanPham_SanPhamID)
                .Index(t => t.HoaDon_HoaDonID)
                .Index(t => t.SanPham_SanPhamID);
            
            CreateTable(
                "dbo.PhanLoaiVatPhams",
                c => new
                    {
                        PhanLoaiVatPhamID = c.Int(nullable: false, identity: true),
                        TenLoaiVatPham = c.String(nullable: false, maxLength: 56),
                        TenLoaiThuCung = c.String(nullable: false, maxLength: 56),
                        VatPham_SanPhamID = c.Int(),
                        LoaiVatPham_LoaiSanPhamID = c.Int(),
                        LoaiThuCung_SanPhamID = c.Int(),
                    })
                .PrimaryKey(t => t.PhanLoaiVatPhamID)
                .ForeignKey("dbo.SanPhams", t => t.VatPham_SanPhamID)
                .ForeignKey("dbo.LoaiSanPhams", t => t.LoaiVatPham_LoaiSanPhamID)
                .ForeignKey("dbo.SanPhams", t => t.LoaiThuCung_SanPhamID)
                .Index(t => t.VatPham_SanPhamID)
                .Index(t => t.LoaiVatPham_LoaiSanPhamID)
                .Index(t => t.LoaiThuCung_SanPhamID);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.PhanLoaiVatPhams", new[] { "LoaiThuCung_SanPhamID" });
            DropIndex("dbo.PhanLoaiVatPhams", new[] { "LoaiVatPham_LoaiSanPhamID" });
            DropIndex("dbo.PhanLoaiVatPhams", new[] { "VatPham_SanPhamID" });
            DropIndex("dbo.CTHoaDons", new[] { "SanPham_SanPhamID" });
            DropIndex("dbo.CTHoaDons", new[] { "HoaDon_HoaDonID" });
            DropIndex("dbo.SanPhams", new[] { "ThongTinThem_ThongTinThemID" });
            DropIndex("dbo.SanPhams", new[] { "LoaiSanPham_LoaiSanPhamID" });
            DropIndex("dbo.SanPhams", new[] { "XuatXu_XuatXuID" });
            DropIndex("dbo.BinhLuanSanPhams", new[] { "User_UserId" });
            DropIndex("dbo.BinhLuanSanPhams", new[] { "SanPham_SanPhamID" });
            DropIndex("dbo.BinhLuanBaiViets", new[] { "UserProfile_UserId" });
            DropIndex("dbo.BinhLuanBaiViets", new[] { "BaiViet_BaiVietID" });
            DropIndex("dbo.BaiViets", new[] { "NguoiViet_UserId" });
            DropIndex("dbo.HoaDons", new[] { "User_UserId" });
            DropForeignKey("dbo.PhanLoaiVatPhams", "LoaiThuCung_SanPhamID", "dbo.SanPhams");
            DropForeignKey("dbo.PhanLoaiVatPhams", "LoaiVatPham_LoaiSanPhamID", "dbo.LoaiSanPhams");
            DropForeignKey("dbo.PhanLoaiVatPhams", "VatPham_SanPhamID", "dbo.SanPhams");
            DropForeignKey("dbo.CTHoaDons", "SanPham_SanPhamID", "dbo.SanPhams");
            DropForeignKey("dbo.CTHoaDons", "HoaDon_HoaDonID", "dbo.HoaDons");
            DropForeignKey("dbo.SanPhams", "ThongTinThem_ThongTinThemID", "dbo.ThongTinThems");
            DropForeignKey("dbo.SanPhams", "LoaiSanPham_LoaiSanPhamID", "dbo.LoaiSanPhams");
            DropForeignKey("dbo.SanPhams", "XuatXu_XuatXuID", "dbo.XuatXus");
            DropForeignKey("dbo.BinhLuanSanPhams", "User_UserId", "dbo.UserProfile");
            DropForeignKey("dbo.BinhLuanSanPhams", "SanPham_SanPhamID", "dbo.SanPhams");
            DropForeignKey("dbo.BinhLuanBaiViets", "UserProfile_UserId", "dbo.UserProfile");
            DropForeignKey("dbo.BinhLuanBaiViets", "BaiViet_BaiVietID", "dbo.BaiViets");
            DropForeignKey("dbo.BaiViets", "NguoiViet_UserId", "dbo.UserProfile");
            DropForeignKey("dbo.HoaDons", "User_UserId", "dbo.UserProfile");
            DropTable("dbo.PhanLoaiVatPhams");
            DropTable("dbo.CTHoaDons");
            DropTable("dbo.ThongTinThems");
            DropTable("dbo.LoaiSanPhams");
            DropTable("dbo.XuatXus");
            DropTable("dbo.SanPhams");
            DropTable("dbo.BinhLuanSanPhams");
            DropTable("dbo.BinhLuanBaiViets");
            DropTable("dbo.BaiViets");
            DropTable("dbo.UserProfile");
            DropTable("dbo.HoaDons");
        }
    }
}
